from typing import List

'''
1.首先，计算出整个数组的和
2.然后，可知道如果存在中心索引的话，那么左边的和的二倍，加上中心索引的值，即等于数组和
3.从左边开始，依次累加，直到找到中心索引
'''


class Solution:

    @staticmethod
    def pivotIndex(nums: List[int]) -> int:
        res = sum(nums)
        lsum = 0
        for i, j in enumerate(nums):
            if lsum * 2 + j == res:
                return i
            lsum += j
        return -1


if __name__ == '__main__':
    nums1 = [1, 7, 3, 6, 5, 6]
    nums2 = [4, 1, 7, 3, 6, 5, 6, 2, 9, 3]
    index = Solution.pivotIndex(nums2)
    print(index)
